<!DOCTYPE html>
{include file="public/link" /}
<div class="kb-build-box">
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-card">
            <div class="layui-card-header">
                <input type="checkbox" name="cover" title="覆盖" lay-skin="tag">
            </div>
            <div class="layui-card-body">
                <div class="kb-build-left">
                    <ul>
                        {foreach $fields as $k=>$v}
                        <li class="{$k==0?'layui-this':''}">
                            <a href="javascript:;" class="layui-bg-gray layui-border">{$v.fields}</a>
                        </li>
                        {/foreach}
                    </ul>
                </div>
                <div class="kb-build-right">
                    {foreach $fields as $k=>$v}
                    <div class="{$k==0?'layui-show':''}" id="{$v.fields}" title="{$v.comments}">
                        <div class="kb-input-inline">
                            <input type="hidden" name="data[{$v.fields}][title]" value="{$v.comments}">
                            <input type="checkbox" name="data[{$v.fields}][table_show]" title="表单显示" lay-skin="tag"
                                lay-filter="table_show">
                            <input type="checkbox" name="data[{$v.fields}][list_show]" title="列表显示" lay-skin="tag">
                            <input type="checkbox" name="data[{$v.fields}][px]" title="支持排序" lay-skin="tag">
                            <input type="checkbox" name="data[{$v.fields}][search]" title="支持查询" lay-skin="tag">
                            <select name="data[{$v.fields}][search_type]">
                                <option value="normal">普通查询</option>
                                <option value="between">范围查询</option>
                                <option value="like">模糊查询</option>
                            </select>
                        </div>
                        <div class="kb-is-table">
                        </div>
                    </div>
                    {/foreach}
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{include file="public/script" /}
<script>
    layui.use(["build"], () => {
        let form = layui.form
        let $ = layui.$
        let layer = layui.layer
        let build = layui.build

        build.render("__admin__/build.json")

        // 提交事件
        form.on('submit(submit)', function (data) {
            let field = data.field; // 获取表单全部字段值
            let index = layer.load(0);
            $.post("", field, function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg, {
                        icon: 1
                    }, function () {
                        parent.location.reload()
                    })
                } else {
                    layer.msg(res.msg)
                }
                layer.close(index)
            })

            return false; // 阻止默认 form 跳转
        });
    })
</script>